<template>
    <div>

        <el-form :model="addClass">

    <el-form-item label="班级名称" :label-width="formLabelWidth">
        <el-input v-model="addClass.className" clearable ></el-input>

        <br>
        <br>
        <el-button @click="adminNull()">重 置</el-button>
        <el-button  v-if="this.id ==null" type="primary" @click="addTbAdmin()">提交</el-button>
        <el-button v-else type="primary" @click="upTbAdmin()">提 交</el-button>

</el-form-item>



  


</el-form>


    </div>
</template>

<script>
import axios from 'axios';

export default {
    data(){
        return{

            id:'',
            grad:[],
            formLabelWidth: '120px', //新增表单宽度
            addClass:{
                "className": "",
                "classWord": "",
                "createTime": "",
                "id": 0,
                "modifyTime": "",
                "num": 0
            }

        }
    },created(){
        this.id = sessionStorage.getItem("id")
        console.log(this.id);

        if(sessionStorage.getItem("id")){
            this.initGetAdminById()
        }

    },
    methods:{

        //回显
         initGetAdminById(){
            axios.get("/api/class/findTbClassById?id="+this.id).then(res=>{
                this.addClass = res.data.data
                sessionStorage.removeItem("id")
            })

        },

        //新增
        addTbAdmin(){
            axios.post("/api/class/addClass",this.addClass).then(res=>{
                //弹框
                this.$message({
                    message: res.data.message,
                    type: 'success'
                    });




            })
        },
        //修改
        upTbAdmin(){
            axios.put("/api/class/updateClass",this.addClass).then(res=>{
                //弹框
                this.$message({
                    message: res.data.message,
                    type: 'success'
                    });
            })


        },

        //重置
         adminNull(){
            this.addadmin ={}
        }

    }
}
</script>